package com.nuanshui.framework.utils;


/**
 * 与操作,位的位置比较
 */
public class PosFlagOperation implements IFlagOperation {
	
	/**
	 * 
	 * @param auth 权限
	 * @param authIndex 要增加的权限
	 */
	public long addFlag(long auth, int authIndex) {
		long i= 1;
		i =  i<<authIndex-1;
		return auth|i;
				
	}
	
	public long removeFlag(long auth,int authIndex) {
		long  i = 1;
		i = i<<authIndex-1;
		i = ~i;
		return auth&i;
		
	}
	
	public boolean containFlag(Long auth,int authIndex) {

		if(auth==null) return false;

		return  internalContainFlag(auth,authIndex);
	}

	public boolean containFlag(long auth,int authIndex) {
		return  internalContainFlag(auth,authIndex);
	}

	private boolean internalContainFlag(long auth,int authIndex) {
		long i= 1;
		i =  i<<authIndex-1;
		auth = auth&i;
        return auth > 0;
    }
	
	public static void main(String[] args) {
		long auth = 2;
		//111    1 2 4
		//System.out.println(addFlag(auth, 3));
		long auth3=6;
		 //System.out.println(addFlag(auth3,10));
//		 System.out.println(delAuth(auth, 9));
//		 System.out.println(delAuth(auth, 9));
		 long  auth2=343;
		 //System.out.println(  hasAuth(auth2, 9));
		// System.out.println(  hasAuth(auth2, 258));
		 
		 
		
	}

}
